<template>
<div class="use-element-visibility">
  <div ref="showBox" class="show-box"></div>
  <div class="status">showBox 是否可见：{{ showBoxVisibility }}</div>
</div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useElementVisibility } from "@vueuse/core";

defineOptions({
  name: "UseElementVisibility"
})
const showBox = ref<HTMLElement | null>(null)
const showBoxVisibility = useElementVisibility(showBox)
</script>

<style scoped lang="css">
.use-element-visibility {
  height: 5000px;
  .show-box {
    width: 100px;
    height: 100px;
    background-color: pink;
  }
  .status {
    position: fixed;
    right: 0;
    bottom: 0;
  }
}
</style>
